from PySide6.QtWidgets import QDialog, QProgressBar, QVBoxLayout, QApplication


class DownloadDialog(QDialog):
    def __init__(self, parent=None, max_value=100):
        super().__init__(parent)

        #最大进度值
        self.max_value = max_value

        #进度
        self.progress = 0

        #模态框参数
        self.setWindowTitle("下载进度")
        self.setFixedSize(300, 100)

        #创建进度条
        self.download_progress = QProgressBar(self)
        #数值范围0-100
        self.download_progress.setMinimum(0)
        self.download_progress.setMaximum(self.max_value)
        #初始值0
        self.download_progress.setValue(0)
        #进度百分比
        self.download_progress.setTextVisible(True)

        #设置布局
        layout = QVBoxLayout()
        layout.addWidget(self.download_progress)
        self.setLayout(layout)

    def update_progress(self, progress):
        print(f"下载进度: {progress}/{self.max_value}")
        self.progress = progress
        self.download_progress.setValue(self.progress)


if __name__ == "__main__":
    app = QApplication([])
    dialog = DownloadDialog(None, 100)
    dialog.show()
    app.exec()
